package com.example.distillapplication.ui.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.distillapplication.R;
import com.example.distillapplication.databinding.FragmentSetBinding;
import com.example.distillapplication.ui.fragment.base.BaseFragment;
import com.example.distillapplication.ui.fragment.viewpager.SetFragmentStateAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

/**
 * A simple {@link Fragment} subclass.
 */
public class SetFragment extends BaseFragment {
    FragmentSetBinding fragmentSetBinding;
    String[] tabTitles={"时间模式","蒸汽量模式"};

    public SetFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_set, container, false);
        fragmentSetBinding = FragmentSetBinding.bind(view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        fragmentSetBinding.viewpager.setAdapter(new SetFragmentStateAdapter(this));
        TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(fragmentSetBinding.tabLayout, fragmentSetBinding.viewpager, true, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabTitles[position]);
                fragmentSetBinding.viewpager.setCurrentItem(tab.getPosition());
            }
        });
        tabLayoutMediator.attach();
    }
}
